<#include '/admin/header.html' >

<style>
.input_text{
	width: 95%;
}
</style>
<div id="loading"></div>
<div class="main">
	<form id="memberform">
		<div id="tb" style="height: auto">
			<a href="javascript:void(0)" class="easyui-linkbutton"
				data-options="plain:true" onclick="newTab('成员添加','${ctx}/core/admin/member/add-view.do')">添加</a>
			<a href="javascript:void(0)" class="easyui-linkbutton"
				data-options="plain:true" onclick="del()">删除</a>
				
			<span style="float: right;"> 
				
				<a href="javascript:void(0)" class="button" id="aAdvanced"  >高级搜索</a>
			</span>
		</div>
		
		<div style="display: block;" class="searchAdvanced" >
		<input id="Advanced" name="Advanced" type="hidden" value="0" />
			<table width="98%" border="0" cellspacing="0" cellpadding="8">
				<tr>
					<th width="70" align="right">学号</th>
					<td>
						<input type="text" value="${student_number!''}" id="student_number"  class="input_text">
					</td>
					
					<th width="70" align="right">手机</th>
					<td>
						<input type=" text" value="${phone!''}" id="mobile" maxlength="11" class="input_text easyui-numberbox">
					</td>
					
					<th width="70" align="right">真实姓名</th>
					<td width="300px">
						<input type="text" value="${real_name!''}" id="real_name"  class="input_text">
					</td>
					
					<th width="70" align="right">昵称</th>
					<td width="300px">
						<input type="text" value="${nick_name!''}" id="nick_name" class="input_text">
					</td>
				</tr>
				<tr>
					<th width="70" align="right">注册时间</th>
					<td width="300px">
						<input class="easyui-datebox" style="width: 90px;height: 28px;" id="start_time" />
                        <span>&nbsp;~&nbsp;</span>
                        <input class="easyui-datebox" style="width: 90px;height: 28px;" id="end_time" />
					</td>
					<th width="70" align="right">年级</th>
					<td width="350px">
						<input type="text" value="${grade!''}" id="grade"  class="input_text">
					</td>
					<th width="70" align="right">性别</th>
					<td>
						<select id="sex" class="inputSelect valid" >
							<option value="2">全部</option>
							<option value="1">男</option>
							<option value="0">女</option>
						</select>
					</td>
				</tr>
				<tr>
					<th width="70" align="right">地址</th>
					<td colspan="3">
						<#include '/admin/address.html' >
					</td>
				</tr>
				<tr>
					<td width="60" align="right"></td>
					<td colspan="7" align="center">
						<a id="searchAdvance" class="button blueButton" onclick="searchMember()" href="javascript:;">开始搜索</a>
						<a class="button blueButton" id="resetInput" href="javascript:;">还原搜索</a>
					</td>
				</tr>
			</table>
		</div>
		<div class="clear height10"></div>
		<div class="shadowBoxWhite tableDiv">
		<table class="easyui-datagrid"
			data-options="url:'${ctx}/core/admin/member/list-json.do',pageList: [5,10,15,20],pageSize:10,fitColumns:'true'"
			pagination="true" id="memberdata" sortName="member_id" sortOrder="desc" >
			<thead>
				<tr>
					<th data-options="field:'member_id',checkbox:true"></th>
					<th data-options="field:'student_number',width:200">学号</th>
					<th data-options="field:'real_name',width:200">真实姓名</th>
					<th data-options="field:'grade',width:200">年级</th>
					<th data-options="field:'student_class',width:200">班级</th>
					<th data-options="field:'sex',width:100" formatter="formatSex">性别</th>
					<th data-options="field:'nick_name',width:200">昵称</th>
					<th data-options="field:'phone',width:200">手机号码</th>
					<th data-options="field:'web_lvid',width:200">等级</th>
					<th data-options="field:'lastlogin',width:250" formatter="formatLastlogin">上次登录日期</th>
					<th data-options="field:'action',width:100" formatter="formatAction">操作</th>
					
				</tr>
			</thead>
		</table>
		</div>
	</form>
	<div id="divdia" style="display: none;"></div>

</div>
<script type="text/javascript">


	

	function append(id) {
		var map = {}; // Map map = new HashMap();
		if (!id) {
			map["href"] = "${ctx}/shop/admin/member/add-member.do";
			map["formId"] = "#addForm";
			map["url"] = "${ctx}/shop/admin/member/save-member.do";
			map["title"] = "添加会员";
			map["loadshow"] = "正在添加......";
		} else {
			map["href"] = "${ctx}/shop/admin/member/edit-member.do?memberId=" + id;
			map["formId"] = "#editForm";
			map["url"] = "${ctx}/shop/admin/member/save-edit-member.do";
			map["title"] = "修改会员";
			map["loadshow"] = "正在修改......";
		}
		map["divDialog"] = "#divdia";
		map["gridreload"] = "#memberdata";

		//需要验证的参数
		map["nameId"] = "#name";
		map["urlId"] = "#url";

		addDialog(map);
	}
	function addDialog(map) {
		$("#divdia").show();
		$("#divdia").dialog({
			title : "增加成员",
			width : 600,
			height : 400,
			closed : false,
			cache : false,
			href : map["href"],
			modal : true,
			buttons : [ {
				text : '保存',
				iconCls : 'icon-ok',
				handler : function() {
					submitForm(map);
				}
			}, {
				text : '取消',
				handler : function() {
					$(map["divDialog"]).dialog('close');
				}
			} ]
		});
	}
	function submitForm(map) {
		var formflag = $(map["formId"]).form().form('validate');
		if (formflag) {
			$.Loading.show(map["loadshow"]);
			var options = {
				url : map["url"],
				type : "POST",
				dataType : 'json',
				success : function(result) {
					if (result.result == 1) {
						$.Loading.show(result.message);
						$(map["divDialog"]).dialog('close');
						$(map["gridreload"]).datagrid('reload');
					}
					if (result.result == 0) {
						$.Loading.error(result.message);
					}
					$.Loading.hide();
				},
				error : function(e) {
					alert("出现错误 ，请重试");
				}
			};
			$(map["formId"]).ajaxSubmit(options);
		}
	}

	function clearForm(map) {
		$(map["formId"]).form('clear');
	}

	function formatAction(value, row, index) {
		var val = "<a class='edit' title='查看与修改' href='javascript:void(0);' onclick='newTab(\""
				+ row.real_name
				+ "-信息修改\",\"${ctx}/core/admin/member/detail.do?memberId="
				+ row.member_id + "\")' ></a>";
		return val;
	}

	function formatRegtime(value, row, index) {
		return getFormatDateByLong(value, "yyyy-MM-dd hh:mm:ss");
	}

	function formatLastlogin(value, row, index) {
		
		if(value==null){
			return "";
		}
		
		return getFormatDateByLong(value, "yyyy-MM-dd hh:mm:ss");
	}

	function formatArea(value, row, index) {
		var val = "";
		if (row.province != null && row.province != "请选择") {
			val = val + row.province;
		}
		if (row.city != null && row.city != "请选择") {
			val = val + "-" + row.city;
		}
		if (row.region != null && row.region != "请选择") {
			val = val + "-" + row.region;
		}
		if (val == "") {
			val = "未选择城市";
		}
		return val;
	}

	function formatSex(value, row, index) {
		var val;
		if (value == 0) {
			val = "女";
		} else if(value == 1){
			val = "男";
		}else{
			val = "";
		}
		return val;
	}

	function formatLogin(value, row, index) {
		//暂时不能登录
		//var val = '<a href="member!sysLogin.do?name='
		//		+ row.uname
		//		+ '" target="_blank"><img class="modify" src="images/transparent.gif" >登录</a>';
		//return val;
	}
	function del() {
		var rows = $('#memberdata').datagrid("getSelections");
		if (rows.length < 1) {
			$.Loading.error("请选择要删除的会员");
			return;
		}
		if (!confirm("确认要将删除会员吗？")) {
			return;
		}
		var options = {
			url : "${ctx}/core/admin/member/delete.do",
			type : "POST",
			dataType : 'json',
			success : function(result) {
				$.Loading.success(result.message);
				if (result.result == 1) {
					alert(result.message);
					location.reload();
				}else if(result.result == 0){
					$("body").overhang({
						type: "error",
						message: result.message
					});
				}
			},
			error : function(e) {
				$("body").overhang({
					type: "error",
					message: "请求错误！请重试！"
				});
			}
		};
		$('#memberform').ajaxSubmit(options);
	}

	$(function() {
		$(".searchAdvanced").hide();
		//高级查询按钮
		$("#aAdvanced").click(function() {
			
			if ($("#Advanced").val() == "0") {
				$("#Advanced").val(1);
				$("#simpleSearch").hide();
				//$("#aAdvanced").text("简单搜索")
				$("#aAdvanced").addClass("searchAdvancedS");
			} else {
				$("#Advanced").val(0);
				
				$("#simpleSearch").show();
				//$("#aAdvanced").text("高级搜索");
				$("#aAdvanced").removeClass("searchAdvancedS");
			}
			$(".searchAdvanced").slideToggle("slow");
		});
		
		//还原搜索
	    $("#resetInput").click(function(){
			reset();
		});
	});

	function searchMember() {

		var searchtype = $("#Advanced").val();
		var keyword = $("#searchKeyword").val();

		var start_time = $('#start_time').datebox('getValue');
		var end_time = $('#end_time').datebox('getValue'); 
		if(start_time != '' && end_time != ''){
			if(end_time < start_time){
				$.Loading.error("结束时间不能小于开始时间");
				return ;
			}
		}
		
		
		//如果手动输入日期搜索，需判断输入的内容是否为正确的日期格式。 
		/* //利用正在表达式判断输入的日期格式是否有误。 修改人:DMRain 2015-12-02
		if(start_time != "" || end_time != ""){
			var reg = /^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$/;
			if(!start_time.match(reg) || !end_time.match(reg)){ 
				alert("输入的日期格式有误！");
				return;
			}
		} */
		
		var student_number = $("#student_number").val();
		var phone=$("#phone").val();
		var real_name=$("#real_name").val();
		var nick_name=$("#nick_name").val();
		var grade=$("#grade").val();
		var sex=$("#sex").val();
		var province_id=$(".province_id").val();
		var city_id=$(".city_id").val();
		var region_id=$(".region_id").val();

		$("#memberdata").datagrid('load', {
			stype : searchtype,
			keyword : keyword,
			start_time : start_time,
			end_time : end_time,
			student_number : student_number,
			phone : phone,
			real_name : real_name,
			nick_name : nick_name,
			grade : grade,
			sex : sex,
			page : 1,
			province_id : province_id,
			city_id : city_id,
			region_id : region_id
		});
	}
	
	//初始化高级搜索条件 add_by DMRain 2016-8-31
	function reset(){
		$("#student_number").val("");
		$("#phone").val("");
		$("#real_name").val("");
		$("#nick_name").val("");
		$("#grade").val("");
		$("#start_time").combo('setText','');
		$("#end_time").combo('setText','');
		$("#sex").val(2);
	}
	
	
</script>



<#include '/admin/footer.html' >
